// eslint.config.js
import antfu from '@antfu/eslint-config'
import * as pluginCheckFile from 'eslint-plugin-check-file'
// import pluginPerfectionist from 'eslint-plugin-perfectionist'

export default antfu(
    {
        formatters: {
            /**
             * Format CSS, LESS, SCSS files, also the `<style>` blocks in Vue
             * By default uses Prettier
             */
            css: true,
            /**
             * Format HTML files
             * By default uses Prettier
             */
            html: true,
            /**
             * Format Markdown files
             * Supports Prettier and dprint
             * By default uses Prettier
             */
            markdown: 'prettier',
        },
        ignores: [
            '.history',
            '.husky',
            '.vscode',
            '.idea',
            '.turbo',
            '**/dist*',
            '**/public',
            '**/node_modules',
            '**/origin-components',
        ],
        // Disable jsonc and yaml support
        jsonc: false,

        // Or customize the stylistic rules
        stylistic: {
            indent: 4, // 4, or 'tab'
            quotes: 'single', // or 'double'
        },
        // TypeScript and Vue are auto-detected, you can also explicitly enable them:
        typescript: true,

        unocss: true,

        vue: true,

        yaml: false,
    },
    {
        files: ['**/vite.config.ts', '**/uno.config.ts', 'internal/vite-config/src/index.ts'],
        rules: {
            'node/prefer-global/process': 'off',
        },
    },
    {
        rules: {
            'jsdoc/check-alignment': 'off',
        },
    },
    {
        files: ['src/**/*'],
        name: '文件名和目录名校验',
        plugins: {
            'check-file': pluginCheckFile,
        },
        rules: {
            'check-file/filename-blocklist': 'off',
            'check-file/filename-naming-convention': 'off',
            'check-file/folder-match-with-fex': 'off',
            'check-file/folder-naming-convention': 'off',
            'check-file/no-index': 'off',
            'no-unused-vars': 'error',
        },
    },
    {
        name: 'antfu:imports',
        rules: {
            // 避免循环依赖
            'import/no-cycle': ['error', { maxDepth: 5 }],
            'import/order': 'off',
        },
    },
    {
        name: 'antfu:javascript',
        rules: {
            'no-console': 'off',
        },
    },
    {
        name: 'antfu:typescript:rules',
        rules:
        {
            'no-fallthrough': 'off', // 运行switch语句时，允许case穿透
            // 禁止 enum
            'no-restricted-syntax': [
                'error',
                {
                    message: 'My reason for not using any enums at all',
                    selector: 'TSEnumDeclaration',
                },
            ],
        },
    },
    {
        name: 'antfu:vue:rules',
        rules: {
            // 首个属性贴脸
            'vue/first-attribute-linebreak': ['error', {
                multiline: 'beside',
                singleline: 'beside',
            }],

            // 每行只有一个属性
            'vue/max-attributes-per-line': 'error',

            // html 标签之间需要空行
            'vue/padding-line-between-tags': ['error', [
                { blankLine: 'always', next: '*', prev: '*' },
            ]],
        },
    },
    // {
    //     // 强迫症专用
    //     name: 'antfu:perfectionist',
    //     rules: {
    //         ...pluginPerfectionist.configs['recommended-natural'].rules,
    //         'perfectionist/sort-vue-attributes': 'off',
    //     },
    // },
    {
        ignores: ['**/*.d.ts'],
        name: 'antfu:typescript:rules',
        rules: {
            'curly': 'off',
            'ts/ban-ts-comment': 'off',
            // 优先使用 type
            'ts/consistent-type-definitions': ['error', 'type'],
            'ts/no-use-before-define': 'off',
            'ts/prefer-ts-expect-error': 'off',
        },
    },
    {
        rules: {
            'no-case-declarations': 'off',
        },
    },
)
